package com.myn.springcloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.myh.springcloud.pojo.User;
import com.myh.springcloud.service.IUSerService;

@RestController
public class UserConsumerController {

	// 理解：消费者不应该有service
	// RestTemplate 供我们使用直接调用 注册到spring
	//提供多种便捷访问远程http服务的方法 简单的Restful的服务模板
//	private static final String REST_USER_PREFIX="http://127.0.0.1:8001";
	
	//Ribbon 我们这里的地址应该是一个变量 通过服务名来拿
	
	@Autowired
	private IUSerService userServiceImpl=null;
	
	@RequestMapping("/consumer/user/get/{id}")
	public User getUserById(@PathVariable("id")Long id) {
		return this.userServiceImpl.queryById(id);
	}
	
	@GetMapping("/consumer/user/getAll")
	public List<User> getAll() {
		System.out.println(1);
		return this.userServiceImpl.quertAll();
	}
	
	
	@PostMapping("/consumer/user/add")
	public boolean addUser( User user) {
		return this.userServiceImpl.addUser(user);
	}
	
	@GetMapping("/hello")
	public String addUser1() {
		return "1";
	}
	
}
